#include "../include/taskqueue.h"

int init_taskqueue(taskqueue_t *queue) {
    queue->head = NULL;
    queue->tail = NULL;
    queue->cond = 0;
    return 0;
}

int en_queue(taskqueue_t *queue, int fd) {
    node_t *new_node=(node_t *)calloc(1,sizeof(node_t));
    new_node->fd = fd;

    if(queue->head==NULL)
    {
        queue->head = new_node;
        queue->tail = new_node;
    }else{
        queue->tail->next = new_node;
        queue->tail = new_node;
    }
    ++queue->cond;
    return 0;
}

int del_queue(taskqueue_t *queue) {
    if(queue->head == NULL) {
        return -1; // Queue is empty
    }
    node_t *temp = queue->head;

    queue->head = queue->head->next;
    free(temp);
    --queue->cond;
    return 0;
}

int print_queue(taskqueue_t *queue)
{
    node_t *tmep=queue->head;
    while(tmep!=NULL)
    {
        printf("%d-->",tmep->fd);
        tmep=tmep->next;
    }
    return 0;
}